<template>
  <!--  物料申请表 -->
  <div id="adduser">
    <el-dialog v-loading="loading" title="申请详情" :visible.sync="dialogVisible" width="45%" top="3vh" :close-on-click-modal='false'>
      <div style="width:90%;margin: 0 auto;padding-bottom:20px;">
        <caigou :act="3"></caigou>
        <div style="margin-top:10px;" class="tabbox">
          <span class="sp1"><p class="min">申请人：</p><a class="man">{{datas.username}}</a></span>
        </div>
        <div style="margin-top:10px;" class="tabbox">
          <span class="sp1"><p class="min">部门：</p><a class="man">{{datas.depName}}</a></span>
        </div>
        <div style="margin-top:10px;" class="tabbox">
          <span class="sp1"><p class="min">物品名称：</p><a class="man">{{datas.name}}</a></span>
        </div>
        <div style="margin-top:10px;" class="tabbox">
          <span class="sp1"><p class="min">物品类型：</p><a class="man">{{id_name(datas.typeId,$store.state.user.leidata)}}</a></span>
        </div>
        <div style="margin-top:10px;" class="tabbox">
          <span class="sp1"><p class="min">尺寸：</p><a class="man">{{datas.size}}</a></span>
        </div>
        <div style="margin-top:10px;" class="tabbox">
          <span class="sp1"><p class="min">型号：</p><a class="man">{{datas.model}}</a></span>
        </div>
        <div style="margin-top:10px;" class="tabbox">
          <span class="sp1"><p class="min">申请数量：</p><a class="man">{{datas.amount}}</a></span>
        </div>
        <div style="margin-top:10px;" class="tabbox" v-show="datas.sku">
          <span class="sp1"><p class="min">物料编码：</p><a class="man">{{datas.sku}}</a></span>
        </div>
        <div style="margin-top:10px;height:50px" class="tabbox" v-show="datas.remarks">
          <span class="sp1"><p class="min">物品备注：</p><a class="man">{{datas.remarks}}</a></span>
        </div>
        <div style="margin-top:10px;height:50px" class="tabbox">
          <span class="sp1"><p class="min">申请原因：</p><a class="man">{{datas.purpose}}</a></span>
        </div>
        <div style="margin-top:10px;" class="tabbox">
          <p style="width:80px;text-align:right"><a style="color:red;">* </a>供应商：</p>
          <el-input style='width:79%;margin-left:10px' type="text" placeholder="请输入" v-model="activ.provider" clearable></el-input>
        </div>
        <div style="margin-top:10px;" class="tabbox">
          <p style="width:80px;text-align:right"><a style="color:red;">* </a>单价：</p>
          <el-input style='width:23%;margin-left:10px' type="number" placeholder="请输入" v-model="activ.price" clearable></el-input><a>￥</a>
        </div>
        <div style="margin-top:10px;height:50px" class="tabbox">
          <span class="sp1"><p class="min">总金额：</p><a class="man">{{activ.price*datas.amount}} ￥</a></span>
        </div>

      </div>
      <div style="width:100%;height:40px;margin-top:20px;">
        <div style="width:170px;margin: 0 auto;">
          <el-button type="danger" @click="dialogVisibles = true" >驳回</el-button>
          <el-button type="primary" @click="ty" style='float:right;'>通过</el-button>
        </div>
      </div>
    </el-dialog>

    <el-dialog
      title="请填写驳回理由"
      :visible.sync="dialogVisibles"
      width="30%">
      <el-input
        type="textarea"
        :autosize="{ minRows: 2, maxRows: 8}"
        placeholder="请输入内容"
        v-model="activ_s.reason">
      </el-input>
      <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisibles = false">取 消</el-button>
         <el-button type="primary" @click="bohui">确 定</el-button>
        </span>
    </el-dialog>

  </div>
</template>
<script>
  import caigou from '@/components/MES/steps/caigou.vue'
  import { purchasedo } from '@/api_bast/Finance.js'

  export default {
    name: 'decla_shens',
    components:{caigou},
    computed:{},
    data() {
      return {
        dialogVisibles:false,
        loading:false,
        dialogVisible:false,
        activ_s:{
          reason:'',//驳回理由
        },
        activ:{
          price:'',//单价
          totalPrice:'',//总价
          provider:'',//供应商
        },
        datas:{
           createdBy:'',//     创建人id
           createdTime:'',//   创建时间
           name:'',//          申请采购的物品名称
           typeId:'',//        型号
           amount:'',//;       数量
           model:'',//;        型号
           size:'',//;         尺寸
           provider:'',//;     供应商
           purpose:'',//;      采购原因
           goodsSku:'',//;     如果仓库中有该物品就填，没有就空着，后台自动生成
           remarks:'',//;      备注
           price:'',//         单价
       },
      }
    },
    props:{
      edit:Number
    },
    methods: {
      panertfn(item){
        this.datas = item
        this.Negate();
      },
      Negate(){this.dialogVisible = !this.dialogVisible},//显隐取反
      qin(){//清除数据方法
        this.activ = {
          price:'',//单价
          totalPrice:'',//总价
          provider:'',//供应商
        };
        this.activ_s.reason = '';
      },
      bohui(){//驳回
        if(this.isNull(this.activ_s.reason)){this.$message({message: '请输入 驳回理由',type: 'error'});return false}
        this.gitact(0);
      },
      ty(){
        if(this.isNull(this.activ.provider)){this.$message({message: '请输入 供应商',type: 'error'});return false}
        if(this.isNull(this.activ.price)){this.$message({message: '请输入 单价',type: 'error'});return false};
        this.activ.totalPrice = this.activ.price*this.datas.amount;
        this.gitact(1);
      },
      gitact(i){//提交数据
        this.loading=true;
        purchasedo(this.datas.id,i,((i==1)?this.activ:this.activ_s)).then(response => {
          this.loading = false;
          if(response.code==200){
            this.qin();
            this.$notify.success({title: '完成',message: response.message});
            this.Negate();
            this.dialogVisibles = false;
            this.$parent.git_act();
          }
        })
      },
    },
    mounted() {

    }
  }
</script>

<style scoped>
  .man{
    height: 100%;
    padding: 0 10px;
    /*border: 1px solid #DCDFE6;*/
    font-weight: bold;
  }
  .min{
    width:80px;
    text-align:right;
  }
  .sp1{
    float: left;
  }
  .sp2{
    float: right;
  }
  .tabbox{
    width:100%;
    height:40px;
    line-height: 30px;
    margin-top:23px;
  }
  .tabbox p{
    font-size:14px;
    /*font-weight: bold;*/
    /*color:#000000;*/

    /*margin-right:10px;*/
    float:left;
    overflow: hidden;
    text-overflow:ellipsis;
    white-space: nowrap;
    font-family:Source Han Sans CN;
  }
</style>
